
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>redis学习笔记 · JAVA学习积累</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="tianwyam">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="redis_list_second_kill.html" />
    
    
    <link rel="prev" href="../SQL/sql.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://blog.csdn.net/mybook201314" target="_blank" class="custom-link">博客Blog</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        <li class="header">【前言】</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    介绍ABOUT
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第一章】Java基础</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../java/java.html">
            
                <a href="../java/java.html">
            
                    
                    计算机基础-操作系统-进程-计算机网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../java/java_thread_pool.html">
            
                <a href="../java/java_thread_pool.html">
            
                    
                    线程池的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../java/java_ftp.html">
            
                <a href="../java/java_ftp.html">
            
                    
                    FTP文件服务器上传下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../java/collection.html">
            
                <a href="../java/collection.html">
            
                    
                    集合
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../java/collection/java_collection_map.html">
            
                <a href="../java/collection/java_collection_map.html">
            
                    
                    Map&HashMap&HashTable&ConcurrentHashMap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="../java/java_queue.html">
            
                <a href="../java/java_queue.html">
            
                    
                    队列-queue
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="../java/java_tree.html">
            
                <a href="../java/java_tree.html">
            
                    
                    二叉树遍历
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../java/java_io_nio.html">
            
                <a href="../java/java_io_nio.html">
            
                    
                    java输入输出流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../java/java_exception.html">
            
                <a href="../java/java_exception.html">
            
                    
                    异常exception
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../java/java_serialize.html">
            
                <a href="../java/java_serialize.html">
            
                    
                    Java序列化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../java/Java_annotation.html">
            
                <a href="../java/Java_annotation.html">
            
                    
                    注解
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../java/multi.html">
            
                <a href="../java/multi.html">
            
                    
                    多线程
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../java/multithread/java_multi_thread_volatile_synchronized.html">
            
                <a href="../java/multithread/java_multi_thread_volatile_synchronized.html">
            
                    
                    volatile&synchronized
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../java/multithread/java_multi_thread_object_wait_notify.html">
            
                <a href="../java/multithread/java_multi_thread_object_wait_notify.html">
            
                    
                    object/wait/notify
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="../java/multithread/java_multi_thread_thread.html">
            
                <a href="../java/multithread/java_multi_thread_thread.html">
            
                    
                    thread
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="../java/multithread/java_multi_thread_threadpool.html">
            
                <a href="../java/multithread/java_multi_thread_threadpool.html">
            
                    
                    线程池的工作原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="../java/multithread/java_multi_thread_lock.html">
            
                <a href="../java/multithread/java_multi_thread_lock.html">
            
                    
                    lock&ReentrantLock&ReadWriteLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.6" data-path="../java/multithread/java_multi_thread_lock_condition.html">
            
                <a href="../java/multithread/java_multi_thread_lock_condition.html">
            
                    
                    lock&condition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.7" data-path="../java/multithread/java_multi_thread_tools.html">
            
                <a href="../java/multithread/java_multi_thread_tools.html">
            
                    
                    Java并发工具- CountDownLatch&CyclicBarrier 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.8" data-path="../java/multithread/java_multi_thread_tools2.html">
            
                <a href="../java/multithread/java_multi_thread_tools2.html">
            
                    
                    Java同步工具类- CountDownLatch&CyclicBarrier&Semaphore  
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../java/java_jvm.html">
            
                <a href="../java/java_jvm.html">
            
                    
                    java虚拟机-JVM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../java/java_java7new.html">
            
                <a href="../java/java_java7new.html">
            
                    
                    java7新知识- Switch&TWR&Objects 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../java/java_stream.html">
            
                <a href="../java/java_stream.html">
            
                    
                    Java8对集合流操作stream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../java/java_stream_groupby.html">
            
                <a href="../java/java_stream_groupby.html">
            
                    
                    java8新语法-Stream-分组groupingBy操作 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../java/java_optional.html">
            
                <a href="../java/java_optional.html">
            
                    
                    java8新语法-Optional 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../java/java_8new_date_api.html">
            
                <a href="../java/java_8new_date_api.html">
            
                    
                    java8-新的日期时间API 
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="6.1" data-path="../xml/xml_translation.html">
            
                <a href="../xml/xml_translation.html">
            
                    
                    XML中特殊符号的转译 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="../datastructure/binary_complement.html">
            
                <a href="../datastructure/binary_complement.html">
            
                    
                    原码、反码、补码 
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="7.1" data-path="../java/basic/javabean2map.html">
            
                <a href="../java/basic/javabean2map.html">
            
                    
                    Java bean转Map 
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第二章】算法积累题</li>
        
        
    
        <li class="chapter " data-level="8.1" data-path="../algorithm/merge_sorted_array.html">
            
                <a href="../algorithm/merge_sorted_array.html">
            
                    
                    算法题 - 合并排序数组 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="../algorithm/lowest_score.html">
            
                <a href="../algorithm/lowest_score.html">
            
                    
                    算法题 - 最低分数线问题 
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="../algorithm/array_sub_list.html">
            
                <a href="../algorithm/array_sub_list.html">
            
                    
                    算法题 - 求数组的子集合 
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第三章】框架</li>
        
        
    
        <li class="chapter " data-level="9.1" data-path="../Spring/springboot.html">
            
                <a href="../Spring/springboot.html">
            
                    
                    SpringBoot
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="../Spring/spring_security.html">
            
                <a href="../Spring/spring_security.html">
            
                    
                    SpringSecurity
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="../linux/linux_commands_springboot_startup.html">
            
                <a href="../linux/linux_commands_springboot_startup.html">
            
                    
                    SpringBoot项目启动脚本
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="10.1" data-path="../Spring/spring/spring_interview_questions_68.html">
            
                <a href="../Spring/spring/spring_interview_questions_68.html">
            
                    
                    Spring面试题68
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="11.1" data-path="../Spring/springboot_auto_config.html">
            
                <a href="../Spring/springboot_auto_config.html">
            
                    
                    SpringBoot自动装载机制 - 源码分析
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="12.1" data-path="../Spring/spring_feign.html">
            
                <a href="../Spring/spring_feign.html">
            
                    
                    Feign在spring、springboot下使用
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="13.1" data-path="../Spring/spring_freemarker.html">
            
                <a href="../Spring/spring_freemarker.html">
            
                    
                    Spring boot集成freemarker，生成word文件
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="14.1" data-path="../Spring/spring_freemarker_generate.html">
            
                <a href="../Spring/spring_freemarker_generate.html">
            
                    
                    Freemarker自动生成Java bean代码
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="15.1" data-path="../mybatis/mybatis_metadata.html">
            
                <a href="../mybatis/mybatis_metadata.html">
            
                    
                    mybatis中操作元数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="15.2" data-path="../mybatis/mybatis_batch_exec_sql.html">
            
                <a href="../mybatis/mybatis_batch_exec_sql.html">
            
                    
                    mybatis中insert/update/delete标签中执行多条SQL语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="15.3" data-path="../mybatis/mybatis_plus.html">
            
                <a href="../mybatis/mybatis_plus.html">
            
                    
                    springboot集成mybatis-plus框架
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="16.1" data-path="../distributed/sharding-jdbc.html">
            
                <a href="../distributed/sharding-jdbc.html">
            
                    
                    【分布式】sharding-jdbc实现分库分表
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第四章】数据库</li>
        
        
    
        <li class="chapter " data-level="17.1" data-path="../SQL/sql.html">
            
                <a href="../SQL/sql.html">
            
                    
                    SQL常用使用
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter active" data-level="18.1" data-path="redis_study_notes.html">
            
                <a href="redis_study_notes.html">
            
                    
                    redis学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="18.2" data-path="redis_list_second_kill.html">
            
                <a href="redis_list_second_kill.html">
            
                    
                    Redis中的队列list实现秒杀活动抢购
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="19.1" data-path="../SQL/sql_mysql_green_install.html">
            
                <a href="../SQL/sql_mysql_green_install.html">
            
                    
                    mysql绿色版安装服务教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.2" data-path="../SQL/sql_h2.html">
            
                <a href="../SQL/sql_h2.html">
            
                    
                    H2内嵌数据的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.3" data-path="../SQL/cache.html">
            
                <a href="../SQL/cache.html">
            
                    
                    缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="19.4" data-path="../SQL/mysql/mysql_back_rollback.html">
            
                <a href="../SQL/mysql/mysql_back_rollback.html">
            
                    
                    MySQL单表备份还原
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第五章】Web</li>
        
        
    
        <li class="chapter " data-level="20.1" data-path="../web/web_js_jquery.html">
            
                <a href="../web/web_js_jquery.html">
            
                    
                    web简单积累
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第六章】Linux</li>
        
        
    
        <li class="chapter " data-level="21.1" data-path="../linux/linux_common_commands.html">
            
                <a href="../linux/linux_common_commands.html">
            
                    
                    linux常用命令
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第七章】Windows</li>
        
        
    
        <li class="chapter " data-level="22.1" data-path="../windows/windows_common_commands.html">
            
                <a href="../windows/windows_common_commands.html">
            
                    
                    windows常用命令
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">【第八章】错误集</li>
        
        
    
        <li class="chapter " data-level="23.1" data-path="../error/maven_not_found_local_jar.html">
            
                <a href="../error/maven_not_found_local_jar.html">
            
                    
                    maven引入依赖时识别不到本地仓库的jar
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="24.1" data-path="../error/security_not_configure_antMatchers_after_anyRequest.html">
            
                <a href="../error/security_not_configure_antMatchers_after_anyRequest.html">
            
                    
                    spring security 配置发生错误 Can't configure antMatchers after anyRequest
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="25.1" data-path="../error/AOP_stream_close_error.html">
            
                <a href="../error/AOP_stream_close_error.html">
            
                    
                    AOP内获取了对请求流操作后报流已经关闭错误的问题
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="26.1" data-path="../tools/github/github_ssh.html">
            
                <a href="../tools/github/github_ssh.html">
            
                    
                    Github ssh key 解决提交后push频繁输入用户名和密码
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="27.1" data-path="../error/sharding-jdbc-error-datasources.html">
            
                <a href="../error/sharding-jdbc-error-datasources.html">
            
                    
                    sharding-jdbc-4.1.1版本启动数据源报错问题
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >redis学习笔记</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#redis-&#x5B66;&#x4E60;&#x7B14;&#x8BB0;"><b></b>Redis &#x5B66;&#x4E60;&#x7B14;&#x8BB0;</a></li><ul><li><span class="title-icon "></span><a href="#1&#x3001;&#x5E38;&#x7528;&#x7684;&#x547D;&#x4EE4;"><b></b>1&#x3001;&#x5E38;&#x7528;&#x7684;&#x547D;&#x4EE4;</a></li><ul><li><span class="title-icon "></span><a href="#11&#x3001;string"><b></b>1.1&#x3001;string</a></li><li><span class="title-icon "></span><a href="#12&#x3001;map"><b></b>1.2&#x3001;map</a></li><li><span class="title-icon "></span><a href="#13&#x3001;list"><b></b>1.3&#x3001;list</a></li><li><span class="title-icon "></span><a href="#14&#x3001;set"><b></b>1.4&#x3001;set</a></li><li><span class="title-icon "></span><a href="#15&#x3001;sorted-set"><b></b>1.5&#x3001;sorted set</a></li></ul><li><span class="title-icon "></span><a href="#2&#x3001;&#x4E8B;&#x52A1;"><b></b>2&#x3001;&#x4E8B;&#x52A1;</a></li><li><span class="title-icon "></span><a href="#3&#x3001;&#x4EFB;&#x52A1;&#x961F;&#x5217;"><b></b>3&#x3001;&#x4EFB;&#x52A1;&#x961F;&#x5217;</a></li><li><span class="title-icon "></span><a href="#4&#x3001;&#x53D1;&#x5E03;&#x8BA2;&#x9605;"><b></b>4&#x3001;&#x53D1;&#x5E03;/&#x8BA2;&#x9605;</a></li><li><span class="title-icon "></span><a href="#5&#x3001;&#x6301;&#x4E45;&#x5316;"><b></b>5&#x3001;&#x6301;&#x4E45;&#x5316;</a></li><ul><li><span class="title-icon "></span><a href="#51&#x3001;rdb&#x65B9;&#x5F0F;"><b></b>5.1&#x3001;RDB&#x65B9;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#52&#x3001;aof&#x65B9;&#x5F0F;"><b></b>5.2&#x3001;AOF&#x65B9;&#x5F0F;</a></li></ul><li><span class="title-icon "></span><a href="#6&#x3001;&#x96C6;&#x7FA4;"><b></b>6&#x3001;&#x96C6;&#x7FA4;</a></li><ul><li><span class="title-icon "></span><a href="#61&#x3001;&#x590D;&#x5236;"><b></b>6.1&#x3001;&#x590D;&#x5236;</a></li></ul></ul></ul></div><h1 id="redis-&#x5B66;&#x4E60;&#x7B14;&#x8BB0;"><a name="redis-&#x5B66;&#x4E60;&#x7B14;&#x8BB0;" class="anchor-navigation-ex-anchor" href="#redis-&#x5B66;&#x4E60;&#x7B14;&#x8BB0;"><i class="fa fa-link" aria-hidden="true"></i></a>Redis &#x5B66;&#x4E60;&#x7B14;&#x8BB0;</h1>
<h2 id="1&#x3001;&#x5E38;&#x7528;&#x7684;&#x547D;&#x4EE4;"><a name="1&#x3001;&#x5E38;&#x7528;&#x7684;&#x547D;&#x4EE4;" class="anchor-navigation-ex-anchor" href="#1&#x3001;&#x5E38;&#x7528;&#x7684;&#x547D;&#x4EE4;"><i class="fa fa-link" aria-hidden="true"></i></a>1&#x3001;&#x5E38;&#x7528;&#x7684;&#x547D;&#x4EE4;</h2>
<h3 id="11&#x3001;string"><a name="11&#x3001;string" class="anchor-navigation-ex-anchor" href="#11&#x3001;string"><i class="fa fa-link" aria-hidden="true"></i></a>1.1&#x3001;string</h3>
<p>&#x200B;    &#x5B57;&#x7B26;&#x4E32;&#xFF08;value&lt;=512MB&#xFF09;</p>
<pre><code class="lang-shell">## &#x8BBE;&#x7F6E;key 
set key value  

## &#x83B7;&#x53D6;
get key  

## &#x5220;&#x9664;
del key 

## &#x5224;&#x65AD;&#x7C7B;&#x578B;
type key     

## &#x5F53;&#x5B58;&#x50A8;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x6574;&#x6570;&#x7C7B;&#x578B;&#xFF0C;&#x8BA9;&#x952E;&#x503C;&#x9012;&#x589E;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x9012;&#x589E;&#x540E;&#x7684;&#x503C;
## &#xFF08;key&#x4E0D;&#x5B58;&#x5728;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;0&#xFF1B;&#x4E0D;&#x662F;&#x6574;&#x578B;&#xFF0C;&#x5219;&#x62A5;&#x9519;&#xFF09;
incr key  

## &#x4EE5;num&#x4E3A;&#x6B65;&#x957F;&#x9012;&#x589E;
incrby key num  

## &#x9012;&#x51CF;
decr key  

## &#x4EE5;num&#x4E3A;&#x6B65;&#x957F;&#x9012;&#x51CF;
decrby key num  

## &#x5411;&#x5C3E;&#x90E8;&#x589E;&#x52A0;
append key value  

## &#x83B7;&#x53D6;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x957F;&#x5EA6;
strlen key
</code></pre>
<h3 id="12&#x3001;map"><a name="12&#x3001;map" class="anchor-navigation-ex-anchor" href="#12&#x3001;map"><i class="fa fa-link" aria-hidden="true"></i></a>1.2&#x3001;map</h3>
<p>&#x6563;&#x5217;&#x7C7B;&#x578B;</p>
<pre><code class="lang-shell">
## &#x8D4B;&#x503C;
hset key field value  

## &#x53D6;&#x503C;
hget key field  
hmset key field value [field value &#x2026;]
hmget key field [field &#x2026;]

## &#x83B7;&#x53D6;key&#x7684;&#x6240;&#x6709;&#x5B57;&#x6BB5;
hgetall key  

## &#x5224;&#x65AD;key&#x7684;&#x5B57;&#x6BB5;&#x662F;&#x5426;&#x5B58;&#x5728;
hexists key field  

## &#x5B58;&#x5728;&#xFF0C;&#x5219;&#x4E0D;&#x505A;&#x5904;&#x7406;&#xFF1B;&#x4E0D;&#x5B58;&#x5728;&#x5B57;&#x6BB5;&#xFF0C;&#x5219;&#x6DFB;&#x52A0;&#x5B57;&#x6BB5;&#x5E76;&#x8D4B;&#x503C;
hsetnx key field value  

## &#x6570;&#x503C;&#x7C7B;&#x578B;&#x589E;&#x52A0;
hincrby key field increment  

## &#x5220;&#x9664;&#x5B57;&#x6BB5;
hdel key field [field &#x2026;.]  

##  &#x83B7;&#x53D6;key&#x7684;&#x6240;&#x6709;&#x5B57;&#x6BB5;
hkeys key  

## &#x83B7;&#x53D6;key&#x7684;&#x6240;&#x6709;&#x5B57;&#x6BB5;&#x503C;
hvals key  

## &#x83B7;&#x53D6;key&#x7684;&#x5B57;&#x6BB5;&#x6570;
hlen key
</code></pre>
<h3 id="13&#x3001;list"><a name="13&#x3001;list" class="anchor-navigation-ex-anchor" href="#13&#x3001;list"><i class="fa fa-link" aria-hidden="true"></i></a>1.3&#x3001;list</h3>
<p>(&#x5217;&#x8868;&#x7C7B;&#x578B;)
&#x200B;    &#x53EF;&#x4EE5;&#x5B58;&#x50A8;&#x6709;&#x5E8F;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x5217;&#x8868;&#xFF08;&#x5411;&#x5217;&#x8868;&#x4E24;&#x7AEF;&#x6DFB;&#x52A0;/&#x5220;&#x9664;&#x5143;&#x7D20;&#xFF09;&#xFF0C;&#x5185;&#x90E8;&#x662F;&#x4F7F;&#x7528;&#x53CC;&#x5411;&#x94FE;&#x8868;&#x5B9E;&#x73B0;&#x7684;</p>
<pre><code class="lang-bash">
<span class="hljs-comment">## -- &#x5217;&#x8868;&#x5DE6;&#x8FB9;&#x6DFB;&#x52A0;</span>
lpush key value [value &#x2026;.]  

<span class="hljs-comment">## -- &#x5217;&#x8868;&#x53F3;&#x8FB9;&#x6DFB;&#x52A0;</span>
rpush key value [value &#x2026;.]  

<span class="hljs-comment">## -- &#x5DE6;&#x8FB9;&#x5F39;&#x51FA;&#x5143;&#x7D20;</span>
lpop key  

<span class="hljs-comment">## -- &#x53F3;&#x8FB9;&#x5F39;&#x51FA;&#x5143;&#x7D20;</span>
rpop key  

<span class="hljs-comment">## -- &#x83B7;&#x53D6;key&#x5217;&#x8868;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x4E2A;&#x6570;</span>
llen key  

<span class="hljs-comment">## -- &#x83B7;&#x53D6;key&#x5217;&#x8868;&#x4E2D;start&#x5230;end&#x4E4B;&#x95F4;&#x7684;&#x5143;&#x7D20;&#xFF08;&#x4E0B;&#x6807;&#x4ECE;0&#x5F00;&#x59CB;&#x7684;&#x3001;&#x5305;&#x62EC;&#x4E24;&#x7AEF;&#xFF09;</span>
lrange key start end  
        start -- end &lt; 0 , &#x5219;&#x8868;&#x793A;&#x4ECE;&#x53F3;&#x8FB9;&#x5F00;&#x59CB;

<span class="hljs-comment">## --  &#x5220;&#x9664;&#x5217;&#x8868;key&#x4E2D;&#x7684;&#x524D;count&#x7684;&#x503C;&#x4E3A;value&#x7684;&#x5143;&#x7D20;</span>
lrem key count value  
    count &gt; 0 &#xFF0C;&#x5219;&#x8868;&#x793A;&#x4ECE;&#x5DE6;&#x8FB9;&#x5F00;&#x59CB;
    count &lt; 0 &#xFF0C;&#x5219;&#x8868;&#x793A;&#x4ECE;&#x53F3;&#x8FB9;&#x5F00;&#x59CB;
    count = 0 &#xFF0C;&#x5219;&#x5220;&#x9664;&#x6240;&#x6709;&#x503C;&#x4E3A;value&#x7684;&#x5143;&#x7D20;

<span class="hljs-comment">## --&#x83B7;&#x53D6;&#x5217;&#x8868;key&#x7D22;&#x5F15;&#x4E3A;index&#x7684;&#x503C;</span>
lindex key index 

<span class="hljs-comment">## &#x2013; &#x8BBE;&#x7F6E;&#x5217;&#x8868;key&#x4E2D;&#x7D22;&#x5F15;&#x503C;&#x4E3A;index&#x7684;&#x503C;&#x4E3A;value</span>
lset key index value 

<span class="hljs-comment">## &#x2013; &#x622A;&#x53D6;&#x5217;&#x8868;key&#x4E2D;start&#x5230;end&#x4E4B;&#x95F4;&#x7684;&#x503C;</span>
ltrim key start end 

<span class="hljs-comment">## --  &#x5411;&#x5217;&#x8868;key&#x4E2D;&#x5728;&#x503C;&#x4E3A;pivot&#x524D;/&#x540E;&#x63D2;&#x5165;value</span>
linsert key before/after pivot value  
    <span class="hljs-comment">##&#x5982;&#xFF1A;linsert sum before 7 3 , &#x8868;&#x793A;&#x5411;sum&#x5217;&#x8868;&#x4E2D;&#x5728;&#x503C;&#x4E3A;7&#x4E4B;&#x524D;&#x63D2;&#x5165;3</span>


<span class="hljs-comment">## -- &#x5C06;&#x4E00;&#x4E2A;&#x5217;&#x8868;&#x79FB;&#x5230;&#x53E6;&#x4E00;&#x4E2A;&#x5217;&#x8868;&#xFF08;&#x5F53;source=dest&#x65F6;&#xFF0C;&#x5FAA;&#x73AF;&#x4E0D;&#x65AD;&#x5C06;&#x961F;&#x5C3E;&#x5143;&#x7D20;&#x79FB;&#x5230;&#x961F;&#x9996;&#x53BB;&#xFF09;</span>
rpoplpush <span class="hljs-built_in">source</span> dest
</code></pre>
<h3 id="14&#x3001;set"><a name="14&#x3001;set" class="anchor-navigation-ex-anchor" href="#14&#x3001;set"><i class="fa fa-link" aria-hidden="true"></i></a>1.4&#x3001;set</h3>
<p>(&#x96C6;&#x5408;&#x7C7B;&#x578B;)
&#x200B;        &#x5185;&#x5BB9;&#x4E0D;&#x91CD;&#x590D;</p>
<pre><code class="lang-bash"><span class="hljs-comment">## -- &#x589E;&#x52A0;&#x5143;&#x7D20;</span>
sadd key member [member &#x2026;..]  

<span class="hljs-comment">## -- &#x5220;&#x9664;&#x5143;&#x7D20;</span>
srem key member [member &#x2026;.]  

<span class="hljs-comment">## -- &#x83B7;&#x53D6;&#x96C6;&#x5408;key&#x4E2D;&#x6240;&#x6709;&#x5143;&#x7D20;</span>
smembers key  

<span class="hljs-comment">## -- &#x5224;&#x65AD;&#x96C6;&#x5408;key&#x4E2D;&#x662F;&#x5426;&#x5305;&#x542B;member&#x5143;&#x7D20;    </span>
sismember key member  

<span class="hljs-comment">## -- &#x5DEE;&#x8FD0;&#x7B97;</span>
sdiff key [key &#x2026;..]  

<span class="hljs-comment">## -- &#x4EA4;&#x96C6;</span>
sinter key [key &#x2026;.]  

<span class="hljs-comment">## -- &#x5E76;&#x96C6;</span>
sunion key [key &#x2026;..]  
        <span class="hljs-comment">##&#xFF08;&#x5176;&#x4E2D;&#x64CD;&#x4F5C;&#x540E;&#xFF0C;&#x539F;&#x96C6;&#x5408;&#x5185;&#x5BB9;&#x4E0D;&#x53D8;&#xFF09;</span>

<span class="hljs-comment">## -- &#x83B7;&#x53D6;&#x96C6;&#x5408;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x4E2A;&#x6570;</span>
scard key
</code></pre>
<h3 id="15&#x3001;sorted-set"><a name="15&#x3001;sorted-set" class="anchor-navigation-ex-anchor" href="#15&#x3001;sorted-set"><i class="fa fa-link" aria-hidden="true"></i></a>1.5&#x3001;sorted set</h3>
<p>(&#x6709;&#x5E8F;&#x96C6;&#x5408;&#x7C7B;&#x578B;)</p>
<h4 id="151&#x3001;&#x6DFB;&#x52A0;"><a name="151&#x3001;&#x6DFB;&#x52A0;" class="anchor-navigation-ex-anchor" href="#151&#x3001;&#x6DFB;&#x52A0;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.1&#x3001;&#x6DFB;&#x52A0;</h4>
<pre><code class="lang-bash"><span class="hljs-comment">## &#x2013; &#x5411;&#x96C6;&#x5408;key&#x4E2D;&#x6DFB;&#x52A0;&#x5206;&#x6570;&#x4E3A;score,&#x5143;&#x7D20;&#x4E3A;member</span>
zadd key score member [score member &#x2026;.] 

<span class="hljs-comment">## -- &#x5411;&#x96C6;&#x5408;key&#x4E2D;&#x7684;member&#x5143;&#x7D20;&#x7684;&#x503C;&#x52A0;&#x4E0A;increment</span>
zincrby key increment member
</code></pre>
<h4 id="152&#x3001;&#x83B7;&#x53D6;"><a name="152&#x3001;&#x83B7;&#x53D6;" class="anchor-navigation-ex-anchor" href="#152&#x3001;&#x83B7;&#x53D6;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.2&#x3001;&#x83B7;&#x53D6;</h4>
<pre><code class="lang-bash"><span class="hljs-comment">## &#x2013; &#x83B7;&#x53D6;&#x96C6;&#x5408;key&#x4E2D;&#x5143;&#x7D20;&#x4E3A;member&#x7684;&#x5206;&#x6570;</span>
zscore key member         

<span class="hljs-comment">## -- &#x83B7;&#x53D6;&#x96C6;&#x5408;key&#x7684;start&#x548C;end&#x95F4;&#x7684;&#x5143;&#x7D20;/&#x643A;&#x5E26;&#x5206;&#x6570;&#xFF08;&#x9ED8;&#x8BA4;&#x5C0F;&#x5230;&#x5927;&#x987A;&#x5E8F;&#xFF09;</span>
zrange key start end [withscores] 

zrevrange key start end [withscores] &#x2013; &#xFF1A;&#x5927;&#x5230;&#x5C0F;

<span class="hljs-comment">## -- &#x83B7;&#x53D6;&#x96C6;&#x5408;key&#x4E2D;min&#x5230;max&#x4E4B;&#x95F4;&#x7684;&#x6210;&#x7EE9;(&#x9ED8;&#x8BA4;&#x5305;&#x62EC;&#x4E24;&#x7AEF;)</span>
zrangebyscore key min max [withscores]  
            <span class="hljs-comment">## &#x5982;&#x679C;&#x4E0D;&#x9700;&#x8981;&#x4E24;&#x7AEF;&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x5728;min/max&#x524D;&#x9762; &#x52A0; &#x2018;(&#x2019;</span>
            -inf  +inf &#x5206;&#x522B;&#x8868;&#x793A;&#x8D1F;&#x65E0;&#x7A77;/&#x6B63;&#x65E0;&#x7A77;

<span class="hljs-comment">## -- &#x83B7;&#x53D6;&#x96C6;&#x5408;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x4E2A;&#x6570;</span>
zcard key  

<span class="hljs-comment">## --  &#x83B7;&#x53D6;min-max&#x5206;&#x6570;&#x8303;&#x56F4;&#x7684;&#x5143;&#x7D20;&#x4E2A;&#x6570;</span>
zcount key min max  

<span class="hljs-comment">## &#x2013; &#x83B7;&#x53D6;&#x6392;&#x540D;(&#x5C0F;&#x5230;&#x5927; &#xFF0C;0&#x5F00;&#x59CB;)        </span>
zrank key member 

<span class="hljs-comment">## &#x2013; (&#x5927;&#x5230;&#x5C0F;&#xFF0C;0&#x5F00;&#x59CB;)</span>
zrevrank key member
</code></pre>
<h4 id="153&#x3001;&#x5220;&#x9664;"><a name="153&#x3001;&#x5220;&#x9664;" class="anchor-navigation-ex-anchor" href="#153&#x3001;&#x5220;&#x9664;"><i class="fa fa-link" aria-hidden="true"></i></a>1.5.3&#x3001;&#x5220;&#x9664;</h4>
<pre><code class="lang-bash"><span class="hljs-comment">## -- &#x5220;&#x9664;&#x5143;&#x7D20;</span>
zrem key member [member &#x2026;.]  

<span class="hljs-comment">## -- &#x5220;&#x9664;start-end&#x4E0B;&#x6807;&#x8303;&#x56F4;&#x7684;&#x5143;&#x7D20;</span>
zremrangebyrank key start end  

<span class="hljs-comment">## -- &#x5220;&#x9664;&#x5206;&#x6570;&#x5728;min-max&#x95F4;&#x7684;&#x5143;&#x7D20;</span>
zremrangebyscore key min max
</code></pre>
<h2 id="2&#x3001;&#x4E8B;&#x52A1;"><a name="2&#x3001;&#x4E8B;&#x52A1;" class="anchor-navigation-ex-anchor" href="#2&#x3001;&#x4E8B;&#x52A1;"><i class="fa fa-link" aria-hidden="true"></i></a>2&#x3001;&#x4E8B;&#x52A1;</h2>
<p>&#x4E00;&#x4E2A;&#x4E8B;&#x52A1;&#x4E2D;&#x7684;&#x547D;&#x4EE4;&#xFF0C;&#x8981;&#x4E48;&#x6267;&#x884C;&#x6210;&#x529F;&#xFF0C;&#x8981;&#x4E48;&#x5C31;&#x90FD;&#x4E0D;&#x6267;&#x884C;&#x3002;</p>
<p>&#x539F;&#x7406;&#xFF1A;&#x5148;&#x5C06;&#x5C5E;&#x4E8E;&#x4E00;&#x4E2A;&#x4E8B;&#x52A1;&#x7684;&#x547D;&#x4EE4;&#x53D1;&#x9001;&#x7ED9;redis&#xFF0C;&#x7136;&#x540E;&#x518D;&#x8BA9;redis&#x4F9D;&#x6B21;&#x6267;&#x884C;&#x8FD9;&#x4E9B;&#x547D;&#x4EE4;&#x3002;</p>
<blockquote>
<p>multi
&#x76F8;&#x5173;&#x547D;&#x4EE4;
exec</p>
</blockquote>
<p>1&#x3001;&#x9519;&#x8BEF;&#x5904;&#x7406;</p>
<p>&#x4E8B;&#x52A1;&#x4E2D;&#x53D1;&#x751F;&#x7684;&#x9519;&#x8BEF;&#x60C5;&#x51B5;&#xFF1A;</p>
<ul>
<li>1&#x3001;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;&#xFF08;&#x90FD;&#x4E0D;&#x4F1A;&#x5141;&#x8BB8;&#xFF09;</li>
<li>2&#x3001;&#x8FD0;&#x884C;&#x9519;&#x8BEF;&#xFF08;&#x6B63;&#x786E;&#x7684;&#x4F1A;&#x5141;&#x8BB8;&#xFF09;</li>
</ul>
<p>2&#x3001;watch</p>
<p>Watch&#x547D;&#x4EE4;&#x53EF;&#x4EE5;&#x76D1;&#x63A7;&#x4E00;&#x4E2A;/&#x591A;&#x4E2A;&#x952E;&#x503C;&#xFF0C;&#x5982;&#x679C;&#x5176;&#x4E2D;&#x6709;&#x88AB;&#x4FEE;&#x6539;&#xFF0C;&#x5219;&#x4E4B;&#x540E;&#x7684;&#x4E8B;&#x52A1;&#x5C31;&#x4E0D;&#x4F1A;&#x88AB;&#x6267;&#x884C;&#x3002;</p>
<blockquote>
<p>watch key [key &#x2026;.]
multi
&#x76F8;&#x5173;&#x547D;&#x4EE4;
exec</p>
</blockquote>
<p>unwatch &#x6765;&#x4FDD;&#x8BC1;&#x4E0B;&#x4E00;&#x4E2A;&#x4E8B;&#x52A1;&#x4E0D;&#x53D7;&#x5F71;&#x54CD;</p>
<p>3&#x3001;&#x8FC7;&#x671F;&#x65F6;&#x95F4;</p>
<pre><code class="lang-bash">
<span class="hljs-comment">## Redis&#x4E2D;&#x4F7F;&#x7528;expire&#x547D;&#x4EE4;&#x6765;&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;&#x952E;&#x7684;&#x8FC7;&#x671F;&#x65F6;&#x95F4;&#xFF0C;&#x5230;&#x65F6;&#x95F4;&#x540E;redis&#x81EA;&#x52A8;&#x5220;&#x9664;</span>
expire key seconds (&#x5355;&#x4F4D;&#x79D2;)
    <span class="hljs-comment">## &#x67E5;&#x770B;&#x952E;&#x7684;&#x5269;&#x4F59;&#x65F6;&#x95F4;&#xFF08;&#x952E;&#x5DF2;&#x4E0D;&#x5B58;&#x5728;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;-2&#xFF1B;&#x6CA1;&#x6709;&#x7ED9; &#x952E;&#x8BBE;&#x7F6E;&#x5931;&#x6548;&#x65F6;&#x95F4;&#xFF0C;&#x5219;&#x8FD4;-1&#xFF09;</span>
    ttl key  

    <span class="hljs-comment">## &#x53D6;&#x6D88;&#x8FC7;&#x671F;&#x65F6;&#x95F4;&#xFF08;&#x6C38;&#x4E45;&#x6027;&#xFF09;</span>
    persist key
</code></pre>
<h2 id="3&#x3001;&#x4EFB;&#x52A1;&#x961F;&#x5217;"><a name="3&#x3001;&#x4EFB;&#x52A1;&#x961F;&#x5217;" class="anchor-navigation-ex-anchor" href="#3&#x3001;&#x4EFB;&#x52A1;&#x961F;&#x5217;"><i class="fa fa-link" aria-hidden="true"></i></a>3&#x3001;&#x4EFB;&#x52A1;&#x961F;&#x5217;</h2>
<pre><code class="lang-bash">
<span class="hljs-comment">## &#x4F7F;&#x7528;&#x5217;&#x8868;&#x6765;&#x5B9E;&#x73B0;&#x7684;</span>
brpop key timeout  -- &#x4E00;&#x65E6;key&#x4E2D;&#x6709;&#x503C;&#xFF0C;&#x5219;&#x8F93;&#x51FA;

<span class="hljs-comment">## &#x4F18;&#x5148;&#x961F;&#x5217;</span>
<span class="hljs-comment">## &#x2013; &#x540C;&#x65F6;&#x68C0;&#x6D4B;&#x591A;&#x4E2A;&#x952E;&#xFF0C;&#x4E00;&#x65E6;&#x5176;&#x4E2D;&#x4E00;&#x4E2A;&#x952E;&#x6709;&#x503C;&#xFF0C;&#x5219;&#x4F1A;&#x88AB;&#x5F39;&#x51FA;&#x3002;</span>
blpop key [key &#x2026;..] timeout
</code></pre>
<h2 id="4&#x3001;&#x53D1;&#x5E03;&#x8BA2;&#x9605;"><a name="4&#x3001;&#x53D1;&#x5E03;&#x8BA2;&#x9605;" class="anchor-navigation-ex-anchor" href="#4&#x3001;&#x53D1;&#x5E03;&#x8BA2;&#x9605;"><i class="fa fa-link" aria-hidden="true"></i></a>4&#x3001;&#x53D1;&#x5E03;/&#x8BA2;&#x9605;</h2>
<pre><code class="lang-bash">
<span class="hljs-comment">## &#x53D1;&#x5E03;&#x8005;&#xFF1A; </span>
publish channel message

<span class="hljs-comment">## &#x8BA2;&#x9605;&#x8005;&#xFF1A; </span>
subscribe channel [channel &#x2026;..]

<span class="hljs-comment">## &#x2013; &#x53D6;&#x6D88;&#x8BA2;&#x9605;(&#x5982;&#x679C;&#x6CA1;&#x6709;&#x52A0;&#x9891;&#x9053;&#x53F7;&#xFF0C;&#x5219;&#x53D6;&#x6D88;&#x6240;&#x6709;)</span>
unsubscribe [channel &#x2026;..]
</code></pre>
<h2 id="5&#x3001;&#x6301;&#x4E45;&#x5316;"><a name="5&#x3001;&#x6301;&#x4E45;&#x5316;" class="anchor-navigation-ex-anchor" href="#5&#x3001;&#x6301;&#x4E45;&#x5316;"><i class="fa fa-link" aria-hidden="true"></i></a>5&#x3001;&#x6301;&#x4E45;&#x5316;</h2>
<h3 id="51&#x3001;rdb&#x65B9;&#x5F0F;"><a name="51&#x3001;rdb&#x65B9;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#51&#x3001;rdb&#x65B9;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>5.1&#x3001;RDB&#x65B9;&#x5F0F;</h3>
<p>RDB&#x65B9;&#x5F0F;&#x7684;&#x6301;&#x4E45;&#x5316;&#x662F;&#x901A;&#x8FC7;&#x5FEB;&#x7167;&#x5B8C;&#x6210;&#x7684;&#x3002; &#x5F53;&#x7B26; &#x5408;&#x4E00;&#x5B9A;&#x7684;&#x6761;&#x4EF6;&#x65F6;Redis&#x4F1A;&#x81EA;&#x52A8;&#x5C06;&#x5185;&#x5B58;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x6570;&#x636E;&#x751F;&#x6210;&#x4E00;&#x4EFD;&#x526F;&#x672C;&#x5E76;&#x4FDD;&#x5B58;&#x5728;&#x78C1;&#x76D8;&#x4E0A;&#xFF0C;&#x8FD9;&#x4E2A;&#x8FC7;&#x7A0B;&#x5373;&#x4E3A;&#x5FEB;&#x7167;&#x3002;(dump.rdb)</p>
<p>&#x4EE5;&#x4E0B;&#x51E0;&#x79CD;&#x6761;&#x4EF6;&#x4E0B;&#x4F1A;&#x5BF9;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x5FEB;&#x7167;&#xFF1A;
1&#x3001;&#x6839;&#x636E;&#x914D;&#x7F6E;&#x89C4;&#x5219;&#x8FDB;&#x884C;&#x81EA;&#x52A8;&#x5FEB;&#x7167;
2&#x3001;&#x7528;&#x6237;&#x6267;&#x884C;save&#x6216;&#x8005;bgsave&#x547D;&#x4EE4;
3&#x3001;&#x6267;&#x884C;flushall&#x547D;&#x4EE4;
4&#x3001;&#x6267;&#x884C;&#x590D;&#x5236;replication&#x65F6;</p>
<h4 id="511&#x3001;&#x6839;&#x636E;&#x914D;&#x7F6E;&#x89C4;&#x5219;&#x8FDB;&#x884C;&#x81EA;&#x52A8;&#x5FEB;&#x7167;"><a name="511&#x3001;&#x6839;&#x636E;&#x914D;&#x7F6E;&#x89C4;&#x5219;&#x8FDB;&#x884C;&#x81EA;&#x52A8;&#x5FEB;&#x7167;" class="anchor-navigation-ex-anchor" href="#511&#x3001;&#x6839;&#x636E;&#x914D;&#x7F6E;&#x89C4;&#x5219;&#x8FDB;&#x884C;&#x81EA;&#x52A8;&#x5FEB;&#x7167;"><i class="fa fa-link" aria-hidden="true"></i></a>5.1.1&#x3001;&#x6839;&#x636E;&#x914D;&#x7F6E;&#x89C4;&#x5219;&#x8FDB;&#x884C;&#x81EA;&#x52A8;&#x5FEB;&#x7167;</h4>
<p>&#x5728;&#x5B89;&#x88C5;&#x914D;&#x7F6E;&#x6587;&#x4EF6;redis.conf&#x4E2D;&#xFF1A;
save 900 1
save 300 10
save 60 1000</p>
<p>save&#x547D;&#x4EE4;&#x914D;&#x7F6E;&#x6709;&#x4FE9;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;save M N /M&#x662F;&#x65F6;&#x95F4;&#xFF0C;N&#x662F;&#x6539;&#x52A8;&#x952E;&#x7684;&#x4E2A;&#x6570;&#x3002;</p>
<p>&#x5373;&#xFF1A;900&#x79D2;&#x5185;&#x6709;&#x4E00;&#x4E2A;&#x6216;&#x4E00;&#x4E2A;&#x4EE5;&#x4E0A;&#x7684;&#x952E;&#x88AB;&#x66F4;&#x6539;&#x4E86;&#x5219;&#x8FDB;&#x884C;&#x5FEB;&#x7167;</p>
<h4 id="512&#x3001;&#x7528;&#x6237;&#x6267;&#x884C;save&#x6216;&#x8005;bgsave&#x547D;&#x4EE4;"><a name="512&#x3001;&#x7528;&#x6237;&#x6267;&#x884C;save&#x6216;&#x8005;bgsave&#x547D;&#x4EE4;" class="anchor-navigation-ex-anchor" href="#512&#x3001;&#x7528;&#x6237;&#x6267;&#x884C;save&#x6216;&#x8005;bgsave&#x547D;&#x4EE4;"><i class="fa fa-link" aria-hidden="true"></i></a>5.1.2&#x3001;&#x7528;&#x6237;&#x6267;&#x884C;save&#x6216;&#x8005;bgsave&#x547D;&#x4EE4;</h4>
<p>1&#x3001;save&#x547D;&#x4EE4;
&#x6267;&#x884C;save&#x547D;&#x4EE4;&#x65F6;&#xFF0C;redis&#x540C;&#x6B65;&#x7684;&#x8FDB;&#x884C;&#x5FEB;&#x7167;&#x529F;&#x80FD;&#xFF0C;&#x4F1A;&#x963B;&#x585E;&#x6240;&#x6709;&#x6765;&#x81EA;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x8BF7;&#x6C42;&#x3002;&#x5C3D;&#x91CF;&#x907F;&#x514D;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4F7F;&#x7528;</p>
<p>2&#x3001;bgsave&#x547D;&#x4EE4;
&#x624B;&#x52A8;&#x6267;&#x884C;&#x5FEB;&#x7167;&#x65F6;&#xFF0C;&#x63A8;&#x8350;&#x4F7F;&#x7528;bgsave&#x547D;&#x4EE4;&#x3002;Bgsave&#x547D;&#x4EE4;&#x53EF;&#x4EE5;&#x5728;&#x540E;&#x53F0;&#x5F02;&#x6B65;&#x6267;&#x884C;&#x3002;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;lastsave&#x547D;&#x4EE4;&#x6765;&#x83B7;&#x53D6;&#x6700;&#x8FD1;&#x4E00;&#x6B21;&#x6210;&#x529F;&#x6267;&#x884C;&#x5FEB;&#x7167;&#x7684;&#x65F6;&#x95F4;&#xFF0C;&#x8FD4;&#x56DE;&#x7684;&#x7ED3;&#x679C;&#x662F;&#x4E00;&#x4E2A;&#x65F6;&#x95F4;&#x6233;</p>
<h4 id="513&#x3001;&#x6267;&#x884C;flushall&#x547D;&#x4EE4;"><a name="513&#x3001;&#x6267;&#x884C;flushall&#x547D;&#x4EE4;" class="anchor-navigation-ex-anchor" href="#513&#x3001;&#x6267;&#x884C;flushall&#x547D;&#x4EE4;"><i class="fa fa-link" aria-hidden="true"></i></a>5.1.3&#x3001;&#x6267;&#x884C;flushall&#x547D;&#x4EE4;</h4>
<p>&#x6267;&#x884C;&#x8BE5;&#x547D;&#x4EE4;&#x65F6;&#xFF0C;redis&#x4F1A;&#x6E05;&#x9664;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x6570;&#x636E;&#x3002;&#x53EA;&#x8981;&#x81EA;&#x52A8;&#x5FEB;&#x7167;&#x6761;&#x4EF6;&#x4E0D;&#x4E3A;&#x7A7A;&#xFF0C;redis&#x90FD;&#x4F1A;&#x6267;&#x884C;&#x4E00;&#x6B21;&#x5FEB;&#x7167;&#x64CD;&#x4F5C;&#x3002;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x5B9A;&#x4E49;&#x81EA;&#x52A8;&#x5FEB;&#x7167;&#x6761;&#x4EF6;&#xFF0C;&#x5219;&#x6267;&#x884C;&#x6B64;&#x547D;&#x4EE4;&#x662F;&#xFF0C;&#x4E0D;&#x4F1A;&#x8FDB;&#x884C;&#x5FEB;&#x7167;&#x3002;</p>
<h4 id="514&#x3001;&#x6267;&#x884C;&#x590D;&#x5236;replication&#x65F6;"><a name="514&#x3001;&#x6267;&#x884C;&#x590D;&#x5236;replication&#x65F6;" class="anchor-navigation-ex-anchor" href="#514&#x3001;&#x6267;&#x884C;&#x590D;&#x5236;replication&#x65F6;"><i class="fa fa-link" aria-hidden="true"></i></a>5.1.4&#x3001;&#x6267;&#x884C;&#x590D;&#x5236;replication&#x65F6;</h4>
<p>&#x6267;&#x884C;&#x590D;&#x5236;&#x64CD;&#x4F5C;&#x65F6;&#xFF0C;&#x65E0;&#x8BBA;&#x6709;&#x6CA1;&#x6709;&#x5B9A;&#x4E49;&#x81EA;&#x52A8;&#x5FEB;&#x7167;&#x6761;&#x4EF6;&#xFF0C;&#x6216;&#x8005;&#x65E0;&#x8BBA;&#x6709;&#x6CA1;&#x6709;&#x624B;&#x52A8;&#x6267;&#x884C;&#x8FC7;&#x5FEB;&#x7167;&#x64CD;&#x4F5C;&#xFF0C;&#x90FD;&#x4F1A;&#x751F;&#x6210;RDB&#x5FEB;&#x7167;&#x6587;&#x4EF6;</p>
<h3 id="52&#x3001;aof&#x65B9;&#x5F0F;"><a name="52&#x3001;aof&#x65B9;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#52&#x3001;aof&#x65B9;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>5.2&#x3001;AOF&#x65B9;&#x5F0F;</h3>
<p>AOF&#xFF08;append only file&#xFF09;&#x53EF;&#x4EE5;&#x5C06;redis&#x6267;&#x884C;&#x7684;&#x6BCF;&#x4E00;&#x6761;&#x5199;&#x547D;&#x4EE4;&#x8FFD;&#x52A0;&#x5230;&#x786C;&#x76D8;&#x6587;&#x4EF6;&#x4E2D;&#x3002;(appendonly.aof)</p>
<h4 id="521&#x3001;&#x5F00;&#x542F;aof"><a name="521&#x3001;&#x5F00;&#x542F;aof" class="anchor-navigation-ex-anchor" href="#521&#x3001;&#x5F00;&#x542F;aof"><i class="fa fa-link" aria-hidden="true"></i></a>5.2.1&#x3001;&#x5F00;&#x542F;AOF</h4>
<p>&#x200B;    appendonly yes&#xFF08;&#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x53EF;&#x4EE5;&#x4FEE;&#x6539;&#xFF09;</p>
<p>&#x200B;    AOF&#x6587;&#x4EF6;&#x4EE5;&#x7EAF;&#x6587;&#x672C;&#x7684;&#x5F62;&#x5F0F;&#x8BB0;&#x5F55;&#x4E86;Redis&#x6267;&#x884C;&#x7684;&#x5199;&#x547D;&#x4EE4;&#x3002;</p>
<h4 id="522&#x3001;&#x540C;&#x6B65;&#x786C;&#x76D8;&#x6570;&#x636E;"><a name="522&#x3001;&#x540C;&#x6B65;&#x786C;&#x76D8;&#x6570;&#x636E;" class="anchor-navigation-ex-anchor" href="#522&#x3001;&#x540C;&#x6B65;&#x786C;&#x76D8;&#x6570;&#x636E;"><i class="fa fa-link" aria-hidden="true"></i></a>5.2.2&#x3001;&#x540C;&#x6B65;&#x786C;&#x76D8;&#x6570;&#x636E;</h4>
<p>&#x200B;    appendfsync always &#x8868;&#x793A;&#x6BCF;&#x6B21;&#x5199;&#x5165;&#x90FD;&#x6267;&#x884C;&#x540C;&#x6B65;
&#x200B;    appendfsync everysec &#x8868;&#x793A;&#x6BCF;&#x4E00;&#x79D2;&#x6267;&#x884C;&#x4E00;&#x6B21;&#x540C;&#x6B65;&#xFF08;&#x9ED8;&#x8BA4;&#xFF09;
&#x200B;    appendfsync no &#x8868;&#x793A;&#x4E0D;&#x4E3B;&#x52A8;&#x6267;&#x884C;&#x540C;&#x6B65;(&#x5373;&#x6BCF;30&#x79D2;&#x6267;&#x884C;&#x4E00;&#x6B21;)</p>
<h2 id="6&#x3001;&#x96C6;&#x7FA4;"><a name="6&#x3001;&#x96C6;&#x7FA4;" class="anchor-navigation-ex-anchor" href="#6&#x3001;&#x96C6;&#x7FA4;"><i class="fa fa-link" aria-hidden="true"></i></a>6&#x3001;&#x96C6;&#x7FA4;</h2>
<h3 id="61&#x3001;&#x590D;&#x5236;"><a name="61&#x3001;&#x590D;&#x5236;" class="anchor-navigation-ex-anchor" href="#61&#x3001;&#x590D;&#x5236;"><i class="fa fa-link" aria-hidden="true"></i></a>6.1&#x3001;&#x590D;&#x5236;</h3>
<p>&#x200B;    Redis&#x63D0;&#x4F9B;&#x4E86;&#x590D;&#x5236;replication&#x529F;&#x80FD;&#xFF0C;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x5F53;&#x4E00;&#x53F0;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x66F4;&#x65B0;&#x540E;&#xFF0C;&#x81EA;&#x52A8;&#x5C06;&#x66F4;&#x65B0;&#x7684;&#x6570;&#x636E;&#x540C;&#x6B65;&#x5230;&#x5176;&#x4ED6;&#x6570;&#x636E;&#x5E93;&#x4E0A;&#x3002;</p>
<p>&#x200B;    &#x4E3B;&#x6570;&#x636E;&#x5E93;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x8BFB;&#x5199;&#x64CD;&#x4F5C;&#xFF0C;&#x5F53;&#x5199;&#x64CD;&#x4F5C;&#x5BFC;&#x81F4;&#x6570;&#x636E;&#x53D8;&#x5316;&#x65F6;&#x4F1A;&#x81EA;&#x52A8;&#x5C06;&#x6570;&#x636E;&#x540C;&#x6B65;&#x7ED9;&#x4ECE;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x800C;&#x4ECE;&#x6570;&#x636E;&#x5E93;&#x4E00;&#x822C;&#x662F;&#x53EA;&#x8BFB;&#x7684;&#xFF0C;&#x5E76;&#x63A5;&#x53D7;&#x4E3B;&#x6570;&#x636E;&#x5E93;&#x540C;&#x6B65;&#x8FC7;&#x6765;&#x7684;&#x6570;&#x636E;&#x3002;
&#xFF08;&#x57FA;&#x4E8E;RDB&#x65B9;&#x5F0F;&#x7684;&#x6301;&#x4E45;&#x5316;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x5373;&#x4E3B;&#x6570;&#x636E;&#x5E93;&#x7AEF;&#x5728;&#x540E;&#x53F0;&#x4FDD;&#x5B58;RDB&#x5FEB;&#x7167;&#xFF0C;&#x4ECE;&#x6570;&#x636E;&#x5E93;&#x7AEF;&#x5219;&#x63A5;&#x53D7;&#x5E76;&#x8F7D;&#x5165;&#x5FEB;&#x7167;&#x6587;&#x4EF6;&#x3002;&#xFF09;
&#x4E00;&#x5BF9;&#x591A;
&#x591A;&#x5BF9;&#x4E00;</p>
<h4 id="611&#x3001;&#x5B9E;&#x73B0;"><a name="611&#x3001;&#x5B9E;&#x73B0;" class="anchor-navigation-ex-anchor" href="#611&#x3001;&#x5B9E;&#x73B0;"><i class="fa fa-link" aria-hidden="true"></i></a>6.1.1&#x3001;&#x5B9E;&#x73B0;</h4>
<p>&#x53EA;&#x9700;&#x8981;&#x5728;&#x4ECE;&#x6570;&#x636E;&#x5E93;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x52A0;&#x5165;&#x4EE5;&#x4E0B;&#x914D;&#x7F6E;&#xFF1A;
&#x200B;    slaveof &#x4E3B;&#x6570;&#x636E;&#x5E93;&#x5730;&#x5740; &#x4E3B;&#x6570;&#x636E;&#x5E93;&#x7AEF;&#x53E3;</p>
<p>&#x6216;&#x8005;
&#x200B;    &#x5728;&#x542F;&#x52A8;&#x670D;&#x52A1;&#x65F6;&#xFF1A;
&#x200B;    redis-server --port 6380 --slaveof 127.0.0.1 6379</p>
<p>&#x6216;&#x8005;
&#x200B;    &#x5728;&#x4ECE;&#x6570;&#x636E;&#x5E93;&#x8FD0;&#x884C;&#x65F6;&#xFF1A;
&#x200B;    slaveof 127.0.0.1 6379
&#x200B;    &#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x547D;&#x4EE4;&#xFF1A;info replication &#x6765;&#x67E5;&#x770B;&#x590D;&#x5236;&#xFF08;&#x4E3B;&#x4ECE;&#x6570;&#x636E;&#x5E93;&#x4FE1;&#x606F;&#xFF09;
&#x200B;    &#x4ECE;&#x6570;&#x636E;&#x5E93;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x547D;&#x4EE4;&#xFF1A;slaveof no one&#x6765;&#x65AD;&#x5F00;&#x4E3B;&#x4ECE;</p>
<footer class="page-footer"><span class="copyright">Copyright @copy tianwyam 2021 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x6700;&#x540E;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-07-25 17:13:09
</span></footer>
                                
                                </section>
                            
                        </div>
                    </div>
                
            </div>

            
                
                <a href="../SQL/sql.html" class="navigation navigation-prev " aria-label="Previous page: SQL常用使用">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="redis_list_second_kill.html" class="navigation navigation-next " aria-label="Next page: Redis中的队列list实现秒杀活动抢购">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"redis学习笔记","level":"18.1","depth":1,"next":{"title":"Redis中的队列list实现秒杀活动抢购","level":"18.2","depth":1,"path":"redis/redis_list_second_kill.md","ref":"redis/redis_list_second_kill.md","articles":[]},"previous":{"title":"SQL常用使用","level":"17.1","depth":1,"path":"SQL/sql.md","ref":"SQL/sql.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","-sharing","github","tbfed-pagefooter","splitter","pageview-count","anchor-navigation-ex","chapter-fold","expandable-chapters-small","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright @copy tianwyam 2021","modify_label":"最后修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"github":{"url":"https://github.com/tianwyam"},"livereload":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":false,"showLevel":false},"pageview-count":{},"expandable-chapters-small":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"tianwyam","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"JAVA学习积累","links":{"sidebar":{"博客Blog":"https://blog.csdn.net/mybook201314"}},"gitbook":"*","description":"积累Java学习过程中的知识点，俗话说：好记性不如烂笔头"},"file":{"path":"redis/redis_study_notes.md","mtime":"2020-07-25T09:13:09.042Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-11-03T12:24:01.188Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

